home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8197 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: beach.and.nl!usenet
  2. From: jos@and.nl (Jos A. Horsmeier)
  3. Newsgroups: comp.lang.pascal.misc,comp.lang.c++,comp.lang.c,comp.lang.pascal.borland
  4. Subject: Re: Tough FACTORIAL math problem...
  5. Date: 15 Feb 1996 17:35:18 GMT
  6. Organization: AND Operations Research B.V.
  7. Message-ID: <4fvqsm$dfm@beach.and.nl>
  8. References: <4fr8be$ass@news.iconn.net> <wzenrwg142.fsf@stego.cs.ruu.nl> <4fvorm$dfm@beach.and.nl>
  9. NNTP-Posting-Host: klepzeiker.and.nl
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <4fvorm$dfm@beach.and.nl>, jos@and.nl goofed:
  15. |In article <wzenrwg142.fsf@stego.cs.ruu.nl>, piet@stego.cs.ruu.nl wrote:
  16.  
  17. ||A little thinking before coding solves this problem very easily:
  18. ||
  19. ||Let N be then number whose factorial you are considering.
  20. ||
  21. ||What you want is the number of trailing zeroes + 1. 
  22. |
  23. |[ clever solution of not-the-posters-problem deleted ... ]
  24. |
  25. |No, that's not what he wanted. A little reading before thinking before
  26. |coding may come in handy sometimes ;-) What the original poster wants
  27. |is the value of the rightmost non-zero digit of n!. 
  28. |
  29. |Let D(n) be the value of the rightmost non-zero digit of number n,
  30. |it is easy to show that D(n!)= D(D(n)*D((n-1)!). Here's function D,
  31. |written in C (it still is c.l.c isn't it?)
  32.  
  33. And a bit of thinking-before-reading-before-thinking-before-coding
  34. is even better most of the times ... darn, I must've had my brains all
  35. backwards; please forget my previous follow-up ... boy, do I feel silly.
  36.  
  37. kind regards,
  38.  
  39. Jos aka jos@and.nl (blushing)
  40. -- 
  41. Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
  42.  
  43.